/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.app.pay.order.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.mapper.JsonMapper;
import com.jeesite.common.service.CrudService;
import com.jeesite.modules.app.pay.order.entity.AppPayOrder;
import com.lly835.bestpay.config.WxPayConfig;
import com.lly835.bestpay.enums.BestPayTypeEnum;
import com.lly835.bestpay.model.PayRequest;
import com.lly835.bestpay.model.PayResponse;
import com.lly835.bestpay.service.impl.BestPayServiceImpl;
import com.jeesite.modules.app.pay.order.dao.AppPayOrderDao;

/**
 * 支付管理Service
 * @author zpp
 * @version 2020-03-13
 */
@Service
@Transactional(readOnly=true)
public class AppPayOrderService extends CrudService<AppPayOrderDao, AppPayOrder> {
	@Autowired
	private BestPayServiceImpl bestPayService;
	/**
	 * 微信支付创建订单
	 * @param order
	 * @param returnUrl
	 */
	private void create(String orderId,String returnUrl,String openId,Double orderAmount){
		//1.使用
		PayRequest payRequest=new PayRequest();
		payRequest.setOpenid(openId);
		payRequest.setOrderAmount(orderAmount);
		payRequest.setOrderId(orderId);
		payRequest.setOrderName("课程购买");
		payRequest.setPayTypeEnum(BestPayTypeEnum.WXPAY_MINI);
		PayResponse pay = bestPayService.pay(payRequest);
		String json = JsonMapper.toJson(pay);
		System.out.println(json);
	}
	/**
	 * 获取单条数据
	 * @param appPayOrder
	 * @return
	 */
	@Override
	public AppPayOrder get(AppPayOrder appPayOrder) {
		return super.get(appPayOrder);
	}
	
	/**
	 * 查询分页数据
	 * @param appPayOrder 查询条件
	 * @param appPayOrder.page 分页对象
	 * @return
	 */
	@Override
	public Page<AppPayOrder> findPage(AppPayOrder appPayOrder) {
		return super.findPage(appPayOrder);
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param appPayOrder
	 */
	@Override
	@Transactional(readOnly=false)
	public void save(AppPayOrder appPayOrder) {
		super.save(appPayOrder);
	}
	
	/**
	 * 更新状态
	 * @param appPayOrder
	 */
	@Override
	@Transactional(readOnly=false)
	public void updateStatus(AppPayOrder appPayOrder) {
		super.updateStatus(appPayOrder);
	}
	
	/**
	 * 删除数据
	 * @param appPayOrder
	 */
	@Override
	@Transactional(readOnly=false)
	public void delete(AppPayOrder appPayOrder) {
		super.delete(appPayOrder);
	}
	
}